package pub.xspace.nova.common.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import pub.xspace.nova.common.constant.Constant;
import pub.xspace.nova.common.domain.AjaxResult;

/**
 * 全局异常处理类
 * 
 * @author HeJianrong
 */
@ControllerAdvice("pub.xspace.nova")
public class GlobalExceptionHandler {

	/**
	 * 通用异常处理方法
	 * 
	 * @param e
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public AjaxResult error(Exception e) {
		return new AjaxResult(Constant.RESULT_FAIL_CODE, Constant.RESULT_FAIL_MSG);
	}

	/**
	 * 自定义异常处理方法
	 * 
	 * @param e
	 * @return
	 */
	@ExceptionHandler(NovaException.class)
	@ResponseBody
	public AjaxResult error(NovaException e) {
		return new AjaxResult(e.getCode(), e.getMsg());
	}
}
